/**Baumklasse
 * 
 * @author Björn Klemm, Gerd Ohlweiler, Anna Macjiewska
 *
 * @param <T> freizuwählender Parameter
 */
public class CompressTree<T extends Comparable<T>> {
	
	private Node anchor;

	private class Node{
		T obj;
		CompressTree left,right;
		
		Node(T obj){
			this.obj = obj;
			left = new CompressTree();
			right = new CompressTree();
		}
	}
	/**Methode zum einfügen eines Objects in einen Baum.
	 * Mit gleichzeitiger Sortierung.
	 * 
	 * @param obj
	 */
	public void insert(final T obj){
		if(anchor == null)
			anchor = new Node(obj);
		else if (obj.compareTo(anchor.obj) < 0){
			anchor.left.insert(obj);
		}
		else 
			anchor.right.insert(obj);
	}
	/**Methode zum Zählen aller vorhanden Knoten im Baum.
	 * 
	 * @return
	 */
	public int getSumOfNodes(){
		int leftNodes = 0, rightNodes = 0;
		if(this.anchor.left != null) { leftNodes = anchor.left.getSumOfNodes();}
		if(this.anchor.right != null) { rightNodes = anchor.right.getSumOfNodes();}
		return 1 + leftNodes + rightNodes;
	}
}
